CHAPTER 11 Comparing Average Values between Groups 151
Importantly, at the top of Listing 11-3, notice that it says “Welch Two Sample
t-test.” This is because R insists on using Welch’s test instead of the Student t test
for independent t tests because Welch’s test accounts for unequal variance (as
well as equal variance) between groups, as discussed earlier. In the output under
the alternative hypothesis, notice that it says R is testing whether the true differ-
ence in means between group 0 and group 1 is not equal to 0 (remember, 1 = married
and 0 = all other marital statuses). R calculated a p value of 4.439e–06, which
resolves to 0.000004439 — definitely p < 0.0001! The groups are definitely statis-
tically significantly different when it comes to average fasting glucose.
But which group is higher? Well, for that, you can look at the last line of the out-
put, where it says that the mean in group 0 (all marital statuses except married)
is 108.8034 mg/dL, and the mean in group 1 (married) is 113.6404 mg/dL. So does
getting married raise your fasting glucose? Before you try to answer that, please
make sure you read up on confounding in Chapter 20!
But what if you just wanted to know if the variance in the fasting glucose mea-
surement in the married group was equal or unequal to the other group, even
though you were doing a Welch test that accommodates both? For that, you can
do an F test. Because we are not sure which group’s fasting glucose would be
higher, we choose a two-sided F test and use this code: var.test(LBXGLU ~
MARRIED, NHANES, alternative = "two.sided"), which produces the output shown in
Listing 11-4.
LISTING 11-4:
R Output from an F Test
> var.test(LBXGLU ~ MARRIED, NHANES, alternative = "two.sided")
F test to compare two variances
data: LBXGLU by MARRIED
F = 0.97066, num df = 2410, denom df = 2332, p-value = 0.4684
alternative hypothesis: true ratio of variances is not equal to$
95 percent confidence interval:
0.8955321 1.0520382
sample estimates:
ratio of variances
0.9706621
As shown in Listing 11-4, the p value on the F test is 0.4684. As a rule of thumb:»
» If p
0 05
.
, you would assume equal variances.»
» If p
0 05
.
, you would assume unequal variances.